//模块
module touch_led(
	input			sys_clk,
	input			sys_rst_n,
	
	input	 		touch_key,
	output	reg		led
);

reg touch_key_d0;
reg touch_key_d1;

wire touch_key_flag;

//上升沿检测
assign touch_key_flag = (~touch_key_d1) & touch_key_d0;

//下降沿检测
//assign touch_key_flag = touch_key_d1 | (~touch_key_d0);

always @(posedge sys_clk or negedge sys_rst_n)	begin
	if(!sys_rst_n)	begin
		touch_key_d0 <= 1'b0;
		touch_key_d1 <= 1'b0;
	end
	else	begin
		touch_key_d0 <= touch_key;
		touch_key_d1 <= touch_key_d0;
	end
end

always @(posedge sys_clk or negedge sys_rst_n)	begin
	if(!sys_rst_n)	
		led <= 1'b0;
	else	begin
		if(touch_key_flag)
			led <= ~led;
		else
			led <= led;
	end
end

endmodule